//
//  CycleBaseCollectionView.h
//  CycleBaseControl
//
//  Created by ddy on 2018/8/14.
//  Copyright © 2018年 cycle. All rights reserved.
//  collectionView基类

#import <UIKit/UIKit.h>

@interface CycleBaseCollectionView : UICollectionView
/**
 * 快速创建一个collectionView含1个cell注册
 */
+ (CycleBaseCollectionView *)cycle_createCollectionViewWithFrame:(CGRect)rect bgColor:(UIColor *)bgColor layout:(UICollectionViewLayout *)layout delegate:(id)delegate dataSource:(id)dataSource isNib:(BOOL)isNib cell:(UICollectionViewCell *)cell identifier:(NSString *)identifier;

@end

/* 亮点：
一： collectionView的headerFooterView的代理设置以及尺寸大小设置
二：collectionView的cell的size代理方法
 
 #import "SPSongAlertViewController.h"
 #import "SPSingAlertModel.h"
 #import "SPSongAlertCollectionViewCell.h"
 #import "SPSongSectionHeaderCollectionReusableView.h"
 #import "SPTicketCollectionReusableViewFooterView.h"
 @interface SPSongAlertViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
 /// 数据模型
 @property (nonatomic , strong) SPSingAlertModel *alertModel;
 /// collectionView
 @property (nonatomic , strong) CycleBaseCollectionView *collectionView;
 /// bgView
 @property (nonatomic , strong) UIView *bgView;
 /// 标题数据
 @property (nonatomic , strong) NSArray *titleArray;
 /// 场次数据数组
 @property (nonatomic , strong) NSArray *ChangCiArray;
 /// 档期数据数组
 @property (nonatomic , strong) NSArray *DangqiArray;
 /// 附加数据数组
 @property (nonatomic , strong) NSArray *fuJiaArray;

 /// 选中的模型(场次，附加)数据
 //@property (nonatomic , strong) NSMutableArray <SPSingAlertSessionsModel *>*selectChangciFuJiaArray;
 ///// 选中的模型(档期)数据
 //@property (nonatomic , strong) NSMutableArray <SPSingAlertSessionsListModel *>*selectDangqiArray;

 /// 场次模型
 @property (nonatomic , strong) SPSingAlertSessionsModel *changciModelV;
 /// 档期模型
 @property (nonatomic , strong) SPSingAlertSessionsListModel *dangQiModelV;
 /// 附加模型
 @property (nonatomic , strong) SPSingAlertSessionsModel *fuJiaModelV;

 /// 确定按钮
 @property (nonatomic , strong) UILabel *sureButton;
 @property (nonatomic , strong) UIButton *sureButton2;

 /// totalPrice
 @property (nonatomic , assign) double totalPrice;
 /// 需要穿的id们
 @property (nonatomic , strong) NSMutableArray *idArray;
 /// 选择的名额
 @property (nonatomic , assign) NSInteger selectNumber;
 ///isTicket : YES 金鸡页面，NO 演唱会论坛
 @property (nonatomic , assign) BOOL isTicket;

 ///isSelectChangci : YES 刷新数量价格，NO （eg：点了档期，附加）数量num不会变
 @property (nonatomic , assign) BOOL isSelectChangci;


 @end
 static NSString * const kHeaderKey = @"SPSongSectionHeaderCollectionReusableViewKEy";
 static NSString * const kFooterKey = @"SPTicketCollectionReusableViewFooterViewKey";


 @implementation SPSongAlertViewController
 #pragma mark --- 懒加载传id参数
 - (NSMutableArray *)idArray {
     if (!_idArray) {
         _idArray = [NSMutableArray array];
     }
     return _idArray;
 }

 //#pragma mark --- 选中的模型(场次，附加)数据
 //- (NSMutableArray <SPSingAlertSessionsModel *>*)selectChangciFuJiaArray {
 //    if (!_selectChangciFuJiaArray) {
 //        _selectChangciFuJiaArray = [NSMutableArray array];
 //    }
 //    return _selectChangciFuJiaArray;
 //}
 //#pragma mark ---  选中的模型(档期)数据
 //- (NSMutableArray <SPSingAlertSessionsListModel *>*)selectDangqiArray {
 //    if (!_selectDangqiArray) {
 //        _selectDangqiArray = [NSMutableArray array];
 //    }
 //    return _selectDangqiArray;
 //}
 #pragma mark --- 确定按钮
 - (UILabel *)sureButton {
     if (!_sureButton) {
         _sureButton = [UILabel new];
         _sureButton.text = @"确定";
         _sureButton.textColor = [UIColor whiteColor];
         _sureButton.font = [UIFont systemFontOfSize:16];
         _sureButton.backgroundColor = kRGBA(104, 33, 227, 1.0);
         _sureButton.textAlignment = NSTextAlignmentCenter;
         
     }
     return _sureButton;
 }
 - (UIButton *)sureButton2 {
     if (!_sureButton2) {
         _sureButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
         ///事件点击
         @weakify(self);
         [[_sureButton2 rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
             @strongify(self);
             NSLog(@"选中的数据id：[%@]     价格:[%.2f]",self.idArray,self.totalPrice);
             if (self.callBackBlock) {
                 self.callBackBlock(self.idArray, self.totalPrice);
             }
             [self dismissViewControllerAnimated:YES completion:nil];
         }];
     }
     return _sureButton2;
 }

 #pragma mark --- 懒加载bgView
 - (UIView *)bgView {
     if (!_bgView) {
         _bgView = [UIView new];
         _bgView.backgroundColor = [UIColor whiteColor];
     }
     return _bgView;
 }
 #pragma mark --- 懒加载collectionView
 - (CycleBaseCollectionView *)collectionView {
     if (!_collectionView) {
         UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
         layout.minimumInteritemSpacing = 10;
         layout.minimumLineSpacing = 10;
         layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
         layout.scrollDirection = UICollectionViewScrollDirectionVertical;
 //        layout.headerReferenceSize = CGSizeMake(100, 50);
 //        layout.footerReferenceSize = CGSizeMake(100, 50);
         _collectionView = [[CycleBaseCollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
         _collectionView.backgroundColor = [UIColor whiteColor];
         _collectionView.delegate = self;
         _collectionView.dataSource = self;
         _collectionView.showsVerticalScrollIndicator = NO;
         _collectionView.showsHorizontalScrollIndicator = NO;
         //注册cell
         [_collectionView registerClass:[SPSongAlertCollectionViewCell class] forCellWithReuseIdentifier:[SPSongAlertCollectionViewCell cycle_reuseCellIdentifier]];
         [_collectionView registerClass:[SPSongSectionHeaderCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderKey];
         [_collectionView registerClass:[SPTicketCollectionReusableViewFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:kFooterKey];
     }
     return _collectionView;
 }

 ///初始化
 - (instancetype)initWithModel:(SPSingAlertModel *)alertModel isTicket:(BOOL)isTicket {
     if (self = [super init]) {
 //        self.isSelectChangci = YES;
         self.isTicket = isTicket;
         self.selectNumber = 1;
         self.alertModel = alertModel;
         self.modalPresentationStyle = UIModalPresentationCustom;
         self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
         //1.取出(每组顶部)标题
         NSMutableArray *titleArray = [NSMutableArray array];
         [titleArray addObject:alertModel.sessions.title];
         [titleArray addObject:alertModel.auctions.title];
         [titleArray addObject:alertModel.subjoins.title];
         self.titleArray = [titleArray mutableCopy];
         //2.1 取出场次数据
         NSMutableArray *changCiArray = [NSMutableArray array];
         if(alertModel.sessions.specifis.count > 0){
             for (NSInteger i = 0; i<alertModel.sessions.specifis.count; i++) {
                 SPSingAlertSessionsModel *changciModel = alertModel.sessions.specifis[i];
 //                [changCiArray addObject:changciModel.sTitle];
                 [changCiArray addObject:changciModel];
             }
             
         }
         self.ChangCiArray = [changCiArray mutableCopy];
         //2.2 取出档期数据，默认第一组
         NSMutableArray *dangqiArray = [NSMutableArray array];
         if (alertModel.sessions.specifis.count > 0) {
             SPSingAlertSessionsModel *model = alertModel.sessions.specifis[0];
             if (model.childList.count > 0) {
                 for (NSInteger i = 0; i < model.childList.count; i++) {
                     SPSingAlertSessionsListModel *listM = model.childList[i];
 //                    [dangqiArray addObject:[NSString stringWithFormat:@"%@(%@)",listM.sTitle,listM.sPrice]];
                     [dangqiArray addObject:listM];
                 }
             }
         }
         self.DangqiArray = [dangqiArray mutableCopy];
         //2.3 取出附加数据
         NSMutableArray *fuJiaArray = [NSMutableArray array];
         if (alertModel.subjoins.specifis.count > 0) {
             for (NSInteger i = 0; i<alertModel.subjoins.specifis.count; i++) {
                 SPSingAlertSessionsModel *fujiaModel = alertModel.subjoins.specifis[i];
 //                [fuJiaArray addObject:changciModel.sTitle];
                 [fuJiaArray addObject:fujiaModel];
             }
         }
         self.fuJiaArray = [fuJiaArray mutableCopy];
         
         
         
         //当选择完成后再次点击弹出清理下上次的选中
         for (SPSingAlertSessionsModel *m1 in self.ChangCiArray) {
             m1.isSelect = NO;
         }
         for (SPSingAlertSessionsListModel *m2 in self.DangqiArray) {
             m2.isSelect = NO;
         }
         for (SPSingAlertSessionsModel *m3 in self.fuJiaArray) {
             m3.isSelect = NO;
         }
     }
     return self;
 }

 #pragma mark --- 系统回调函数
 - (void)viewDidLoad {
     [super viewDidLoad];
     [self.view addSubview:self.bgView];
     [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.mas_equalTo(0);
         make.bottom.mas_equalTo(self.view.mas_bottom);
         make.height.mas_equalTo(kScreenHeight*0.7);
     }];
 //    self.view.backgroundColor = [UIColor redColor];
     //按钮
     [self.view addSubview:self.sureButton];
     [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.mas_equalTo(0);
         make.bottom.mas_equalTo(self.view.sp_safeBottom);
         make.height.mas_equalTo(40);
     }];
     [self.view addSubview:self.sureButton2];
     [self.sureButton2 mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.mas_equalTo(0);
         make.bottom.mas_equalTo(self.view.sp_safeBottom);
         make.height.mas_equalTo(40);
     }];
     //collectionView
     [self.view addSubview:self.collectionView];
     [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.mas_equalTo(0);
         make.bottom.mas_equalTo(self.sureButton.mas_top).offset(-10);
         make.height.mas_equalTo(kScreenHeight*0.7);
     }];
     

 }


 #pragma mark --- UICollectionViewDataSource
 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
 //    return self.titleArray.count;
     return 3;
 }
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
     if (section == 0) {
         //场次
        return self.ChangCiArray.count;
     } else if(section == 1){
         //档期
         return self.DangqiArray.count;
     } else {
         //附加数据
         return self.fuJiaArray.count;
     }
     return 0;
 }

 // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
 - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
     SPSongAlertCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[SPSongAlertCollectionViewCell cycle_reuseCellIdentifier] forIndexPath:indexPath];
     //section
     NSInteger section = indexPath.section;
     if (section == 0) {
         //场次
         SPSingAlertSessionsModel *changciModel = self.ChangCiArray[indexPath.item];
         cell.titleLabel.text = changciModel.sTitle;
         //选中状态
         if (changciModel.isSelect) {
             CycleViewBorderRadius(cell.titleLabel, 20, 1, [UIColor purpleColor]);
             cell.titleLabel.textColor = [UIColor grayColor];
         } else {
             CycleViewBorderRadius(cell.titleLabel, 20, 1, [UIColor lightGrayColor]);
             cell.titleLabel.textColor = [UIColor lightGrayColor];
         }
         //模拟告罄
 //        if(indexPath.item %2==0){
 //            changciModel.sTotalNumber = @"33";
 //            changciModel.sCount = @"33";
 //        }
         
         //判断是否可以点击,灰色,告罄
         if ([changciModel.sTotalNumber doubleValue] - [changciModel.sCount doubleValue] <= 0) {
             //告罄
             CycleViewBorderRadius(cell.titleLabel, 20, 1, SPTextColor240);
             cell.titleLabel.textColor = SPTextColor240;
         }
         
     } else if(section == 1){

         //档期
         SPSingAlertSessionsListModel *dangqiModel = self.DangqiArray[indexPath.item];
         cell.titleLabel.text = [NSString stringWithFormat:@"%@(%@)",dangqiModel.sTitle,dangqiModel.sPrice];
         //选中状态
         if (dangqiModel.isSelect) {
             CycleViewBorderRadius(cell.titleLabel, 20, 1, [UIColor purpleColor]);
             cell.titleLabel.textColor = [UIColor grayColor];
         } else {
             CycleViewBorderRadius(cell.titleLabel, 20, 1, [UIColor lightGrayColor]);
             cell.titleLabel.textColor = [UIColor lightGrayColor];
         }
         //判断是否可以点击,灰色,告罄
         if ([dangqiModel.sTotalNumber doubleValue] - [dangqiModel.sCount doubleValue] <= 0) {
             //告罄
             CycleViewBorderRadius(cell.titleLabel, 20, 1, SPTextColor240);
             cell.titleLabel.textColor = SPTextColor240;
         }
     } else {
         //附加数据
         SPSingAlertSessionsModel *fujiaModel = self.fuJiaArray[indexPath.item];
         cell.titleLabel.text = fujiaModel.sTitle;
         //选中状态
         if (fujiaModel.isSelect) {
             CycleViewBorderRadius(cell.titleLabel, 20, 1, [UIColor purpleColor]);
             cell.titleLabel.textColor = [UIColor grayColor];
         } else {
             CycleViewBorderRadius(cell.titleLabel, 20, 1, [UIColor lightGrayColor]);
             cell.titleLabel.textColor = [UIColor lightGrayColor];
         }
         //判断是否可以点击,灰色,告罄
         if ([fujiaModel.sTotalNumber doubleValue] - [fujiaModel.sCount doubleValue] <= 0) {
             //告罄
             CycleViewBorderRadius(cell.titleLabel, 20, 1, SPTextColor240);
             cell.titleLabel.textColor = SPTextColor240;
         }
     }
     
     return cell;
 }
 #pragma mark --- UICollectionViewDelegate
 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    //section
    NSInteger section = indexPath.section;
     
     BOOL canClick = YES;
     //1.不可以点击
     if (section == 0) {
         //点击的场次
         self.isSelectChangci = YES;
         //场次
         SPSingAlertSessionsModel *changciModel = self.ChangCiArray[indexPath.item];
         //模拟告罄
 //        if(indexPath.item %2==0){
 //            changciModel.sTotalNumber = @"33";
 //            changciModel.sCount = @"33";
 //        }
         //判断是否可以点击,灰色,告罄
         if ([changciModel.sTotalNumber doubleValue] - [changciModel.sCount doubleValue] <= 0) {
             //告罄
             canClick = NO;
         }
         
     } else if(section == 1){
         //点击的档期
         self.isSelectChangci = NO;
         //档期
         SPSingAlertSessionsListModel *dangQiModel = self.DangqiArray[indexPath.item];
         //判断是否可以点击,灰色,告罄
         if ([dangQiModel.sTotalNumber doubleValue] - [dangQiModel.sCount doubleValue] <= 0) {
             //告罄
             canClick = NO;
         }
     } else {
         //点击的附加数据
         self.isSelectChangci = NO;
         //附加
         SPSingAlertSessionsModel *fujiaModel = self.fuJiaArray[indexPath.item];
         //判断是否可以点击,灰色,告罄
         if ([fujiaModel.sTotalNumber doubleValue] - [fujiaModel.sCount doubleValue] <= 0) {
             //告罄
             canClick = NO;
         }
     }
     
     if (canClick == NO)return;
     
     //2.可以点击
     if (section == 0) {
         //场次
         SPSingAlertSessionsModel *changciModel = self.ChangCiArray[indexPath.item];
         NSLog(@"点击 场次,改变档期数据");
         //选中状态
         if (changciModel.isSelect) {
             changciModel.isSelect = NO;
             self.changciModelV = nil;
         } else {
             changciModel.isSelect = YES;
             self.changciModelV = changciModel;
             //清理档期
             self.dangQiModelV = nil;
             //更新数据
             if (changciModel.childList.count > 0) {
                 self.DangqiArray = changciModel.childList;
             }
         }
         //如果当前数据被选中，则数据里面其他数据不能被选中,保证单选
         if (changciModel.isSelect) {
             //场次
             for (SPSingAlertSessionsModel *model in self.ChangCiArray) {
                 if (![model isEqual:changciModel]) {
                     model.isSelect = NO;
                 }
             }
             //重新选择场次后 因为要刷新档期数据 档期状态需要清空从新选择
             for (SPSingAlertSessionsListModel *model in self.DangqiArray) {
                 model.isSelect = NO;
             }
         } else {
             //取消选中
             for (SPSingAlertSessionsModel *model in self.ChangCiArray) {
                     model.isSelect = NO;
             }
         }
 //        //收集最终结果
 //        if (changciModel.isSelect) {
 //            //当前的数据储存起来
 //            //添加选中的数据数据
 //            [self selectWithFuJiaChangciIsAdd:YES model:changciModel];
 //            //取消添加选中的数据数据
 //            for (SPSingAlertSessionsModel *model in self.ChangCiArray) {
 //                if (![model.id isEqualToString:changciModel.id]) {
 //                    [self selectWithFuJiaChangciIsAdd:NO model:model];
 //                }
 //            }
 //        } else {
 //            //其他的都去掉
 //            [self selectWithFuJiaChangciIsAdd:NO model:changciModel];
 //        }
     } else if(section == 1){
         //档期
         SPSingAlertSessionsListModel *dangqiModel = self.DangqiArray[indexPath.item];
        NSLog(@"点 档期");
         //选中状态
         if (dangqiModel.isSelect) {
             dangqiModel.isSelect = NO;
             self.dangQiModelV = nil;
         } else {
             dangqiModel.isSelect = YES;
             self.dangQiModelV = dangqiModel;
         }
         //如果当前数据被选中，则数据里面其他数据不能被选中,保证单选
         if (dangqiModel.isSelect) {
             for (SPSingAlertSessionsListModel *model in self.DangqiArray) {
                 if (![model isEqual:dangqiModel]) {
                     model.isSelect = NO;
                 }
             }
         } else {
             for (SPSingAlertSessionsListModel *model in self.DangqiArray) {
                     model.isSelect = NO;
             }
         }
 //        //收集最终结果
 //        if (dangqiModel.isSelect) {
 //            //当前的数据储存起来
 //            //添加选中的数据数据
 //            [self selectWithDangQiIsAdd:YES model:dangqiModel];
 //            //取消添加选中的数据数据
 //            for (SPSingAlertSessionsListModel *model in self.DangqiArray) {
 //                if (![model.id isEqualToString:dangqiModel.id]) {
 //                    [self selectWithDangQiIsAdd:NO model:model];
 //                }
 //            }
 //        } else {
 //            //其他的都去掉
 //            [self selectWithDangQiIsAdd:NO model:dangqiModel];
 //
 //        }
     } else {
         //附加数据
         SPSingAlertSessionsModel *fujiaModel = self.fuJiaArray[indexPath.item];
        NSLog(@"点击 附加数据");
         //选中状态
         if (fujiaModel.isSelect) {
             fujiaModel.isSelect = NO;
             self.fuJiaModelV = nil;
         } else {
             fujiaModel.isSelect = YES;
             self.fuJiaModelV = fujiaModel;
         }
         //如果当前数据被选中，则数据里面其他数据不能被选中,保证单选
         if (fujiaModel.isSelect) {
             //附加
             for (SPSingAlertSessionsModel *model in self.fuJiaArray) {
                 if (![model isEqual:fujiaModel]) {
                     model.isSelect = NO;
                 }
             }
         } else {
             //取消选中
             for (SPSingAlertSessionsModel *model in self.fuJiaArray) {
                     model.isSelect = NO;
             }
         }
         
 //        //收集最终结果
 //        if (fujiaModel.isSelect) {
 //            //当前的数据储存起来
 //            //添加选中的数据数据
 //            [self selectWithFuJiaChangciIsAdd:YES model:fujiaModel];
 //            //取消添加选中的数据数据
 //            for (SPSingAlertSessionsModel *model in self.fuJiaArray) {
 //                if (![model.id isEqualToString:fujiaModel.id]) {
 //                    [self selectWithFuJiaChangciIsAdd:NO model:model];
 //                }
 //            }
 //        } else {
 //            //其他的都去掉
 //            [self selectWithFuJiaChangciIsAdd:NO model:fujiaModel];
 //        }
     }
     //计算
     [self calulatePrice];
     
     //刷新数据
     [self.collectionView reloadData];
 }
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
     //section
     NSInteger section = indexPath.section;
     double width = 0;
     NSString *titleStr = nil;
     if (section == 0) {
         //场次
         SPSingAlertSessionsModel *changciModel = self.ChangCiArray[indexPath.item];
         titleStr = changciModel.sTitle;
     } else if(section == 1){
         //档期
         SPSingAlertSessionsListModel *dangqiModel = self.DangqiArray[indexPath.item];
         titleStr = [NSString stringWithFormat:@"%@(%@)",dangqiModel.sTitle,dangqiModel.sPrice];
     } else {
         //附加数据
         SPSingAlertSessionsModel *fujiaModel = self.fuJiaArray[indexPath.item];
         titleStr = fujiaModel.sTitle;
     }
     //计算宽度
     width = [titleStr boundingRectWithSize:CGSizeMake(kScreenWidth-30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.width;
     width += 20;//设置左右两边间距10
     return CGSizeMake(width, 40);
 }
 // 设置Header的尺寸
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
      CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
      return CGSizeMake(screenWidth, 50);
 }
  
 // 设置Footer的尺寸
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
     //是否是金鸡
     if (self.isTicket) {
         if(section == 2){
             CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
             return CGSizeMake(screenWidth, 60);
         } else {
             return CGSizeZero;
         }
     } else {
         return CGSizeZero;
     }
     

 }
 ///设置sectionHeader
 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
     UICollectionReusableView *reuseableView = nil;
     if (kind == UICollectionElementKindSectionHeader) {
         SPSongSectionHeaderCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderKey forIndexPath:indexPath];
         header.indexPath = indexPath;
         header.backgroundColor = [UIColor whiteColor];
         header.titleLabel.text = self.titleArray[indexPath.section];
         header.cancelBlock = ^{
           //消失
             [self dismissViewControllerAnimated:YES completion:nil];
         };
         return header;
     } else if(kind == UICollectionElementKindSectionFooter){
         ///如果是金鸡页面，需要显示名额数量
         if (self.isTicket) {
             if (indexPath.section == 2) {
                 //最后一个，添加人数
                 SPTicketCollectionReusableViewFooterView *footer = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:kFooterKey forIndexPath:indexPath];
                 //只需要
                 if (self.isSelectChangci == YES) {
                     if (self.changciModelV != nil) {
                         //选中
                         footer.model = self.changciModelV;
                     } else {
                         //取消
                         [footer resetNumber];
                     }
                     
                 }
                 //回调
                 footer.callBackNum = ^(NSInteger num) {
                     NSLog(@"最终选择的num：%zd",num);
                     self.selectNumber = num;
                     //计算价格
                     [self calulatePrice];
                 };
                 
                 return footer;
             } else {
                 return reuseableView;
             }
         } else {
             //不是金鸡页面（eg：论坛页面，不显示）
             return reuseableView;
         }
         
     }
     return reuseableView;
 }


 //点击消失
 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
     UITouch *touch = [touches anyObject];
     CGPoint point = [touch locationInView:self.view];
     if (!CGRectContainsPoint(self.bgView.frame, point)) {
         [self dismissViewControllerAnimated:YES completion:nil];
     }
 }


 ///计算价格
 - (void)calulatePrice {
     double totalPrice = 0;
     NSMutableArray *IdArray = [NSMutableArray array];
     if (self.changciModelV != nil) {
         [IdArray addObject:self.changciModelV.id];
         totalPrice += [self.changciModelV.sPrice doubleValue];
     }
     if (self.dangQiModelV != nil) {
         [IdArray addObject:self.dangQiModelV.id];
         totalPrice += [self.dangQiModelV.sPrice doubleValue];
     }
     if (self.fuJiaModelV != nil) {
         [IdArray addObject:self.fuJiaModelV.id];
         totalPrice += [self.fuJiaModelV.sPrice doubleValue];
     }
 //    //场次，附加的选中情况
 //    if(self.selectChangciFuJiaArray.count > 0){
 //        for (NSInteger i = 0; i < self.selectChangciFuJiaArray.count; i++) {
 //            SPSingAlertSessionsModel *model = self.selectChangciFuJiaArray[i];
 //            [IdArray addObject:model.id];
 //            totalPrice += [model.sPrice doubleValue];
 //        }
 //
 //    }
 //    //档期的选中情况
 //    if(self.selectDangqiArray.count > 0){
 //        for (NSInteger i = 0; i < self.selectDangqiArray.count; i++) {
 //            SPSingAlertSessionsListModel *listModel = self.selectDangqiArray[i];
 //            [IdArray addObject:listModel.id];
 //            totalPrice += [listModel.sPrice doubleValue];
 //        }
 //    }
     //最终结果
     //计算价格，查看是否是金鸡页面需要乘以人数
     if(self.isTicket){
         totalPrice = totalPrice * self.selectNumber;
     }
     self.totalPrice = totalPrice;
     self.idArray = IdArray;
     
     //设置
     NSDictionary *style = @{@"fontSize1":[UIFont systemFontOfSize:12],@"fontSize2":[UIFont systemFontOfSize:20],@"fontSize3":[UIFont systemFontOfSize:15]};
     self.sureButton.attributedText = [[NSString stringWithFormat:@"<fontSize1>¥</fontSize1><fontSize2>%.2f</fontSize2>   <fontSize3>立即支付</fontSize3>",totalPrice] attributedStringWithStyleBook:style];
     //不可点击
     if (totalPrice == 0) {
         self.sureButton2.enabled = NO;
         self.sureButton.backgroundColor = [UIColor lightGrayColor];
     } else {
         self.sureButton2.enabled = YES;
         self.sureButton.backgroundColor = kRGBA(104, 33, 227, 1.0);;
     }
     
     NSLog(@"%.2f---选中的ID们 [%@]",totalPrice,IdArray);
 }

 @end

 */
